//
//  SGSProfileViewController.m
//  AgileNYC
//
//  Created by German on 02.08.14.
//  Copyright (c) 2014 Softlegion. All rights reserved.
//

#import "SGSProfileViewController.h"
#import "SGSUtils.h"
#import "SGSModelsManager.h"
#import "SGSProfileTableViewController.h"
#import "SGSDelegatesManager.h"
#import "SGSDialogsManager.h"

@interface SGSProfileViewController ()

@end

@implementation SGSProfileViewController

- (instancetype)init
{
    self = [super init];
    if (self) {
        GSLog(GSLogEvent, @"----- SGSProfileViewController inited");
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    SGSDelegatesManager * delegatesManager = [SGSDelegatesManager sharedDelegatesManager];
    delegatesManager.currentProfileVC = self;
    
    self.isNewUser = NO;
    
    [self loadSessionID];
    
    GSLog(GSLogEvent, @"----- SGSProfileViewController did load");
}

#pragma mark - Actions

- (IBAction)onSaveButtonClick:(UIButton *)sender {

    SGSDelegatesManager * delegatesManager = [SGSDelegatesManager sharedDelegatesManager];
    
    SGSProfileTableViewController * profileTabVC = delegatesManager.currentProfileTableVC;
    
    if (profileTabVC) {
        if ([profileTabVC saveProfile]) {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}

- (IBAction)onConnectButtonClick:(id)sender {
    [[SGSDelegatesManager sharedDelegatesManager].currentEventsVC showConnectionDialog];
}

#pragma mark - Internal Functions

-(void) loadSessionID {
    NSString * sessionID = [[SGSModelsManager sharedModelsManager] currentUser].sessionID;
    
    if ((sessionID) && (![sessionID isEqualToString:@"0"]) && (![sessionID isEqualToString:@"(null)"])) {
        self.labSessionID.text = sessionID;
        self.labSessionID.hidden = NO;
    } else {
        self.labSessionID.hidden = YES;
    }
}

-(void) setBackButtonCaption:(NSString*) caption {
    [self.btnSave setTitle:caption forState:UIControlStateNormal];
}

#pragma mark - System Functions

- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];}

@end
